<template>
	<view class="container">
		<view class="log" style="text-align: center; height: 220px;">
			<image src="../../static/images/school1.jpg" style="width: 250px; height: 250px; scale: 0.4;"></image>
		</view>
		<uni-forms ref="form" :model="user" :rules="rules">
			<uni-forms-item label="" name="name">
				<uni-easyinput v-model="user.name" placeholder="请输入用户名" />
			</uni-forms-item>
			<uni-forms-item label="" name="password">
				<uni-easyinput type="password" v-model="user.password" placeholder="请输入密码" />
			</uni-forms-item>
			<uni-forms-item label="" name="">
				<button type="primary" size="default" @click="login">登录</button>
				<button @click="toregister" type="primary">注册</button>
			</uni-forms-item>
		</uni-forms>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				rules: {
					name: {
						rules: [{
							required: true,
							errorMessage: '请填写姓名',
						}]
					},
					password: {
						rules: [{
							required: true,
							errorMessage: '请输入密码',
						}]
					}
				},
				user: {
					name: '',
					password: ''
				}
			}
		},
		methods: {
			toregister() {
				uni.redirectTo({
					url: '../my/register'
				})
			},
			login(e) {
				uni.request({
					url: 'http://localhost:8090/freshmenapp/user/login',
					method: 'POST',
					data: this.user,
					success: res => {
						if (res.data.success) {
							this.list = res.data.list
							uni.showToast({
								title: '成功',
								icon: 'none'
							});
						}
						uni.setStorage({
							key: 'userinfo',
							data: res.data.data
						})
						uni.navigateBack()
					},
					fail: () => {

					},
					complete: () => {

					}
				});
				onLoad: () => {
					uni.onTabBarMidButtonTap(function(e) {
						console.log(e)

					})
				}

				this.$refs.form.validate().then(() => {
					// console.log(e);
					console.log(this.user.name);

				})


			}
		}
	}
</script>

<style>

</style>